
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<span style="font-size:18px;">
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="statusInformation/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="statusInformation/css/commonly-used-show.css" />
    <script type="text/javascript" src="statusInformation/js/jquery.min.js"></script>
    <script type="text/javascript" src="statusInformation/js/bootstrap.js" ></script>
    <title>用户管理</title>

    <style type="text/css">
        td, th {
            text-align: center;
        }
    </style>

</head>
<body class="mybody">

<jsp:include page="theTopMenuAdmin.jsp" />


<div class="container">
    <h3 style="text-align: center">用户信息列表</h3>
    <table border="1" class="table table-bordered table-hover">
        <tr class="success">
            <th>序号</th>
            <th>账号</th>
            <th>用户类型</th>
            <th>编号</th>
            <th>创建时间</th>
            <th>姓名</th>
            <th>性别</th>
            <th>地址</th>
            <th>联系方式</th>
            <th>操作</th>
        </tr>

        <c:forEach items="${alluser}" var="user" varStatus="xh">
            <tr>
                <td>${xh.count}</td>
                <td>${user.userLoginName}</td>
                <c:if test="${user.userLevel == 0}">
                    <td>${"管理员"}</td>
                </c:if>
                <c:if test="${user.userLevel == 1}">
                    <td>${"教师"}</td>
                </c:if>
                <c:if test="${user.userLevel == 2}">
                    <td>${"学生"}</td>
                </c:if>

                <td>${user.createUserId}</td>
                <td>${user.createTime}</td>
                <td>${user.userName}</td>
                <td>${user.userSex}</td>
                <td>${user.userAddress}</td>
                <td>${user.userTel}</td>
                <td><a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/adminUpdateUsers?id=${user.id}">修改</a>&nbsp;<a class="btn btn-default btn-sm" href="#" onclick="deleteUser('${user.id}')">删除</a></td>
            </tr>
        </c:forEach>

        <tr>
            <td colspan="10" align="center"><a class="btn btn-primary" href="${pageContext.request.contextPath}/addUsers">添加用户</a></td>
        </tr>

    </table>
</div>

<script type="text/javascript">
    var userdt = JSON.parse(sessionStorage.getItem("user"));
    if (userdt.result.userName != null){
        $("#usname").text(userdt.result.userName);
    }else {
        $("#usname").text(userdt.result.userLoginName);
    }

    function deleteUser(id){
        var postUrl = "${pageContext.request.contextPath}/deleteUser";
        var str = {
            "id": id
        };
        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status == "0"){
                    alert("删除用户出错")
                }else {
                    //alert("删除用户成功")
                    location.href = "${pageContext.request.contextPath}/administrationManagement";
                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }

</script>

</body>
</html>
</span>